package cc.wsyw126.java.nowcoder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created by junpeng.yang on 17/3/19.
 */
public class MaxPrice {

    class In {
        int b;
        int c;

        public In(int b, int c) {
            this.b = b;
            this.c = c;
        }
    }

    public static void main(String[] args) {
        MaxPrice maxPrice = new MaxPrice();
        List<In> ins = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String next = scanner.nextLine();
            String[] split1 = next.split(" ");
            int n = Integer.valueOf(split1[0]), m = Integer.valueOf(split1[1]);
            String next1 = scanner.nextLine();
            String[] split2 = next1.split(" ");
            for (int i = 0; i < m; i++) {
                String next2 = scanner.nextLine();
                String[] split = next2.split(" ");
                int b = Integer.valueOf(split[0]), c = Integer.valueOf(split[1]);
                In in = maxPrice.new In(b, c);
                ins.add(in);
            }

            int max = 0;
            for (String s : split2) {
                int price = 0, mark = 0, markb = 0;
                Integer integer = Integer.valueOf(s);
                for (int i = 0; i < ins.size(); i++) {
                    if (ins.get(i).b <= integer) {
                        if (ins.get(i).c > price || (ins.get(i).c == price && ins.get(i).b > markb)) {
                            price = ins.get(i).c;
                            mark = i;
                            markb = ins.get(i).b;
                        }
                    }
                }
                ins.remove(mark);
                max += price;
            }
            System.out.println(max);
        }
    }

}
